import Vue from 'vue'
import Router from 'vue-router'

// 1.安装插件
Vue.use(Router)

// 2.创建router
const routes = [{
		path: '',
		redirect: '/home'
	},
	{
		path: '/home',
		component: () => import('@/views/home/home.vue')
	},
	{
		path: '/category',
		component: () => import('@/views/category/category.vue')
	},
	{
		path: '/cart',
		component: () => import('@/views/cart/Cart.vue')
	},
	{
		path: '/proflie',
		component: () => import('@/views/profile/Profile.vue')
	}
]


const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error);
};
//如果以上代码失效，可以把两种都写上，就可以解决了
const originalReplace = Router.prototype.replace;
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};


const router = new Router({
	routes,
	mode: 'history'
})
export default router
